#pragma once

#include "TdBulkConnection.h"
#include "TdColumn.h"
#include "TdUtils.h"

using namespace System::Collections::Generic;
using namespace System::Data::SqlClient;
using namespace System::Runtime::InteropServices;

namespace TdParallelTransportApi {

public ref class TdBulkCopy
{
public:
	TdBulkCopy(TdBulkConnection^ connection);

	void WriteToServer(
		array<TdColumn^>^ sourceColumns,
		IEnumerator<array<System::Object^>^>^ sourceData);

	void TerminateExistingSession(array<TdColumn^>^ sourceColumns);

	void Abort() { this->m_Abort = true; }

	/*property int BatchSize
	{
		int get();
		void set(int value);
	}*/

	property int NotifyAfter
	{
		int get();
		void set(int value);
	}

	property TdLogLevel LogLevel
	{
		TdLogLevel get();
		void set(TdLogLevel value);
	}

	property System::String^ DestinationTableName
	{
		System::String^ get();
		void set(System::String^ value);
	}

	event SqlRowsCopiedEventHandler^ RowsCopied;

	static const int MaxColumns = 256;
private:
	initonly TdBulkConnection^ m_Connection;
	System::String^ m_DestinationTableName;
	//int m_BatchSize;
	int m_NotifyAfter;
	TdLogLevel m_LogLevel;
	System::Boolean m_Abort;

	char *username;
	char *password;
	char *server;
	char *database;
	char *target;
	char *log;
	char * logLevel;
	char **fieldList;
	char* insertStatement;

	void Initialize(array<TdColumn^>^ sourceColumns, int restartmode, void** conn_ptr, void** dmlGr_ptr, void** schema_ptr);
	void CleanUp();
};

}
